package com.halflife.parameter.template;

import com.halflife.comeElectricity.basic.datadic.DataDic;
import com.halflife.comeElectricity.basic.datadic.DataDicRepository;
import com.halflife.comeElectricity.basic.datadic.DataDicType;
import com.halflife.comeElectricity.basic.datadic.DataDicTypeRepository;
import com.halflife.framework.converter.MapHandler;
import com.halflife.framework.domain.Page;
import com.halflife.framework.dto.Result;
import com.halflife.framework.participant.Company;
import com.halflife.framework.participant.CompanyRepository;
import com.halflife.framework.participant.user.UserView;
import com.halflife.shiro.utils.ShiroUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class TemplateFrontController {

    private Logger log = LoggerFactory.getLogger(this.getClass());
    @Resource
    private TemplateRepository templateRepository;
    @Resource
    private DataDicRepository dataDicRepository;
    @Resource
    private DataDicTypeRepository dataDicTypeRepository;
    @Resource
    private CompanysRepository companysRepository;

    @GetMapping("/parameters/options/{key}")
    public Result<DataDic> getOptions(@PathVariable String key, @RequestParam(required = false) HashMap<String,Object> queryParam, Page page, HttpServletResponse response,
                             HttpServletRequest request, Model model) {

        DataDicType dataDicType = dataDicTypeRepository.selectOne("select * from t_datadictype t where t.code='"+key+"'");
        Map<String, Object> params = new HashMap<>();
        params.put("valid", true);
        params.put("dataDicTypeId", dataDicType.getId());
        List<DataDic>  dicList = dataDicRepository.selectAll(params);
        return Result.Ok(dicList);
    }
    @GetMapping("/parameters/company")
    public Result<Company> getCompanys(@RequestParam(required = false) HashMap<String,Object> queryParam, Page page, HttpServletResponse response,
                                       HttpServletRequest request, Model model) {
        Map<String, Object> params = new HashMap<>();
        List<Companys> list = companysRepository.selectAll(params);
        return Result.Ok(list);
    }
}
